package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.ActivityInfoDto;
import com.crm.jdy.common.dto.CallAplanInfoDto;
import com.crm.jdy.common.pojo.ActivityInfo;
import com.crm.jdy.common.pojo.CallAplanInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.ActivityInfoService;
import com.crm.jdy.service.client.CallAplanInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 拜访活动计划API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年1月26日
*
*/
@Validated
@Api(tags = "callAplanInfo", description = "拜访活动计划")
@RestController
@RequestMapping("/callAplanInfo")
public class CallAplanInfoController{

    @Reference(version = "${service.version}", check = false)
    CallAplanInfoService callAplanInfoService;

    @RateLimit()
    @ApiOperation("拜访信息")
    @PostMapping("/seleteCallAplanInfo")
    public ResultVo seleteCallAplanInfo( @RequestBody CallAplanInfoDto callAplanInfoDto){
        PageInfo<CallAplanInfo> list = callAplanInfoService.seleteCallAplanInfo(callAplanInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新拜访计划")
    @PostMapping("/updatCallAplanInfo")
    public ResultVo updatCallAplanInfo(@ApiParam(value = "callAplanInfoDto", required = true)
                                       @Validated @RequestBody CallAplanInfo callAplanInfoDto){
        boolean index = callAplanInfoService.updateCallAplanInfo(callAplanInfoDto);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加拜访计划")
    @PostMapping("/addCallAplanInfo")
    public ResultVo addCallAplanInfo(@ApiParam(name = "callAplanInfo", required = false)
                                     @Validated @RequestBody CallAplanInfo callAplanInfo){
        boolean list  = callAplanInfoService.addCallAplanInfo(callAplanInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除拜访计划")
    @DeleteMapping("deleteCallAplanInfo/{aplanId}")
    public ResultVo deleteCallAplanInfo(@NotNull @ApiParam(name = "aplanId", value = "aplanId", required = true) @PathVariable String aplanId){
        boolean b = callAplanInfoService.removeCallAplanInfo(aplanId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}